#ifndef ________PID_H________
#define ________PID_H________

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus


#include "stdint.h"
#include "stdbool.h"
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "string.h"
#include "stdarg.h"

typedef struct PID_t
{
    // PID参数
    float kp;
    float ki;
    float kd;
    
    // 输出限幅
    float max_output;
    float min_output;
    
    // 积分限幅
    float max_integral;
    float min_integral;
    
    // 微分限幅
    float max_derivative;
    float min_derivative;
    
    // 状态变量
    float integral;
    float derivative;
    float last_error;
    float last_output;  // 上次输出值，用于返回结果
    float last_time;
    
    // 新增：积分分离阈值
    float separation_threshold;
    
} PID_Type;

// 函数声明
void pid_init(PID_Type* pid, float kp, float ki, float kd, 
              float max_output, float min_output,
              float max_integral, float min_integral,
              float max_derivative, float min_derivative,
              float separation_threshold);

void pid_update(PID_Type* pid, float setpoint, float current_value, float current_time);
#ifdef __cplusplus
}
#endif

#endif // ________PID_H________

